﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhSystemBLL.produceBLL;
using dhDataAcess.baseBLL;
using baseSet.importExport;

namespace dhsystem.produceForm.picking
{
    public partial class Frmrlckcheck : Form
    {
        rlckBLL rlck = new rlckBLL();
        string billNo;
        BindingSource BindingSourcerlckMasterAdd;
         
        public Frmrlckcheck(BindingSource BindingSourcerlckMaster, string _billNo)
        {
            InitializeComponent();
            BindingSourcerlckMasterAdd = BindingSourcerlckMaster;
            billNo = _billNo;
        }

        private void Frmrlckcheck_Load(object sender, EventArgs e)
        {
            labelrlckStatus.DataBindings.Add("text", BindingSourcerlckMasterAdd, "billStatus");
            labeldeptNum.DataBindings.Add("text", BindingSourcerlckMasterAdd, "deptName");
            labelworkername.DataBindings.Add("text", BindingSourcerlckMasterAdd, "workername");
            labelbillNo.DataBindings.Add("text", BindingSourcerlckMasterAdd, "billNo");
            labelorderNo.DataBindings.Add("text", BindingSourcerlckMasterAdd, "orderNo");
            labelbillnum.DataBindings.Add("text", BindingSourcerlckMasterAdd, "billnum");
            labelbillDate.DataBindings.Add("text", BindingSourcerlckMasterAdd, "billDate");
            labelstockName.DataBindings.Add("text", BindingSourcerlckMasterAdd, "stockname");
            labelmark.DataBindings.Add("text", BindingSourcerlckMasterAdd, "mark");
            bgSourcescrlDetail.DataSource = rlck.getsrlckDetailAllBybillNo(labelbillNo.Text);
            dGridDetail.DataSource = bgSourcescrlDetail;
            DcolumnSet.colSet(moduleInfo.rltkDetail, dGridDetail);
        }
        //单据终结按钮
        private void toolcheck_Click(object sender, EventArgs e)
        {
            try
            {
                if (basicSql.getrlckStatus(labelbillNo.Text) == "终结")
                {
                    MessageBox.Show("该单据已终结，无需再次终结");
                }
                else
                {
                    DialogResult result = MessageBox.Show("是否终结单据！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        basicSql.getrlckStatusUpdate(labelbillNo.Text, "终结");
                        MessageBox.Show("终结成功");
                        labelrlckStatus.Text = "终结";
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }

        }
        //单据反终结按钮
        private void toolcheckquxiao_Click(object sender, EventArgs e)
        {
            try
            {
                if (basicSql.getrlckStatus(labelbillNo.Text) == "终结")
                {
                    DialogResult result = MessageBox.Show("是否反终结单据！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        basicSql.getrlckStatusUpdate(labelbillNo.Text, "新建");
                        MessageBox.Show("反终结成功");
                        labelrlckStatus.Text = "新建";
                    }


                }
                else
                {
                    MessageBox.Show("订单未审核，不需要反审");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
